<template>
	<!-- 聊天界面展示https://www.bilibili.com/video/BV1hT4y1P75N?p=22  搭建1和2 -->
	<view class="content" >

		<scroll-view class="chat" scroll-y="true" scroll-with-animation="true" :scroll-into-view="scrollToView">
			<view class="chat-main" :style="{paddingBottom:inputh+'px'}">
				<view class="chat-ls" v-for="(item,index) in unshiftmsg" :key="index" :id="'msg'+ index">
					<view class="chat-time" v-if="item.createTime != ''">{{changeTime(item.createTime)}}</view>
					<view class="msg-m msg-left" v-if="!item.isMine">
						<view class="message">
							<view @longpress="copy(item.sendText)" class="msg-text">
								<text>{{item.sendText.replace(/\\n/g,'\n') || '...'}}</text>
							</view>
						</view>
					</view>
					<view class="msg-m msg-right" v-else>
						<view class="message">
							<view class="msg-text">{{item.sendText}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import dateTime from './dateTime.js';
	export default {
		data() {
			return {
				title: 'AI法律解答',
				// 反转数据接收
				unshiftmsg: [],
				scrollToView: '',
				inputh: '100',
			}
		},
		onLoad(e) {
			this.unshiftmsg = JSON.parse(e.item)
			console.log(this.unshiftmsg)
		},
		methods: {
			changeTime(date) {
				return dateTime.dateTime1(date);
			},
		}
	}
</script>

<style lang="scss">
	@import 'dialog.scss'
</style>